package leetcode.code1448;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

public class Solution implements IDebug {

	public int goodNodes(TreeNode root) {
		return this.goodNodes(root, root.val);
	}

	private int goodNodes(TreeNode root, int max) {
		if (root == null) {
			return 0;
		}
		int ans = root.val >= max ? 1 : 0;
		max = Math.max(max, root.val);
		ans += this.goodNodes(root.left, max);
		ans += this.goodNodes(root.right, max);
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
